package com.toe.forum.webapi.ESRepository;

import com.toe.pojo.entity.forum.ArticleElasticsearch;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ArticleElasticsearchRepository extends ElasticsearchRepository<ArticleElasticsearch,Long> {

    // 当前接口继承ElasticsearchRepository父接口后
    // 会自动在类中生成基本的增删改查方法,直接可以使用
    // 它自动识别或自动生成的规则,是我们定义的两个泛型ElasticsearchRepository<[实体类名],[主键类型]>

    //自定义查询
    @Query("{\n" +
            "    \"bool\": {\n" +
            "      \"should\": [\n" +
            "        { \"match\": { \"title\": \"?0\"}},\n" +
            "        { \"match\": { \"authorNickname\": \"?0\"}},\n" +
            "        { \"match\": { \"coryWriting\": \"?0\"}}\n" +
            "        ]\n" +
            "     }\n" +
            "}")
    Iterable<ArticleElasticsearch> querySearch(String keywords);

    @Query("{\n" +
            "    \"bool\": {\n" +
            "      \"should\": [\n" +
            "        { \"match\": { \"title\": \"?0\"}},\n" +
            "        { \"match\": { \"authorNickname\": \"?0\"}},\n" +
            "        { \"match\": { \"coryWriting\": \"?0\"}}\n" +
            "        ]\n" +
            "     }\n" +
            "}")
    Page<ArticleElasticsearch> querySearch(String keywords, Pageable pageable);
}
